<?php


namespace app\admin\controller;

use \app\common\business\SpecsValue as SpecsValueBiz;
class SpecsValue extends AdminBase
{
    public function add() {
        $specsId = $this->request->param('specs_id', 0, 'intval');
        $name = $this->request->param('name', '', 'trim');
        //简单验证
        if ($specsId == 0 || $name == '') {
            return show(config('status.error'), '参数错误');
        }
        $data = [
            'specs_id'=> $specsId,
            'name'=> $name,
            'status'=> 1
        ];
        //添加
        $res = (new SpecsValueBiz())->add($data);
        if ($res) {
            return show(config('status.success'), 'OK', ['id'=> $res]);
        }
        return show(config('status.error'), '操作失败');
    }
    /**
     * 根据ID获取规则下的属性
     * @return \think\response\Json
     */
    public function getBySpecsId() {
        $specsId = $this->request->param('specs_id', 0, 'intval');
        if ($specsId == 0) {
            return show(config('status.error'), '参数错误');
        }
        $res = (new SpecsValueBiz)->getBySpecsId($specsId);
        if ($res) {
            return show(config('status.success'), 'OK', $res);
        }
        return show(config('status.error'), '操作失败');
    }
}